<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>公众号列表</title>
    <style>
        .qrcode{
            padding: 5px;background: #f4f4f4;border: 1px solid #dddddd;cursor: pointer;margin-left: 5px;
        }
    </style>
</head>
<body>
<div class="box">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 公众号管理</a></li>
            <li class="active">公众号列表</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-12">
                        <div id="example1_filter" class="dataTables_length">
                            <label>
                                <input type="search" id="keyword" class="form-control input-sm" placeholder="昵称丶原始ID丶公司" aria-controls="example1">
                            </label>
                            <button type="button" id="search" class="btn  margin" style="background: #18bc9c;color: #ffffff;">搜索</button>
                            <button type="button" onclick="relist()" title="刷新" class="btn bg-aqua margin"><i class="fa fa-refresh"></i></button>
                            <button type="button" class="btn margin"id="test1" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-upload" style="margin-right: 5px;"></i>导入</button>
                            <a href="{$turl}" class="btn bg-orange margin">公众号授权</a>
                            <button type="button" id="btn_del" class="btn bg-red margin"><i class="fa  fa-trash-o"></i> 删除</button>
                            <div class="form-group">
                                <label>分类：</label>
                                <select id="select" class="form-control select2" style="width: 120px;">
                                    <option value="" selected="selected">一级分类</option>
                                    {volist name="category" id="v"}
                                    <option value="{$v.id}">{$v.categoryname}</option>
                                    {/volist}
                                </select>
                                <select id="select2" class="form-control select2" style="width: 120px;">
                                    <option selected="selected">二级分类</option>
                                </select>
                            </div>
                        </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                        <tr role="row">
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                <input id="allchecked" type="checkbox" style="margin-left: 10px">
                            </th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">头像</th>
                            <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 297px;">账号昵称</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 322px;">原始ID</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 257px;">appId</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">一级分类</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">二级分类</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 300px;">消息回复列表</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">是否认证</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">扫码手机</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 297px;">授权时间</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">操作</th>
                        </tr>
                        </thead>
                        <tbody id="tb">
                       </tbody>
                    </table>
                    <div class="layui-row pull-right" id="footpager" align="center"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    var _keyword = '';
    var _category = '';
    var _category2 = '';
    var _page='1';
    var _size='10'
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,accept:'file'
            ,exts:'xlsx'
            ,auto:true
            ,url: '{:url("adminindex/uploadTencent")}' //上传接口
            , before: function (input) {
                loading = layer.load(2, {
                    shade: [0.2, '#000']
                });
            }
            ,done: function(res){
                layer.close(loading);
                if(res.code == 0){
                    layerAlert(res.msg,function(){
                        table.destroy();
                        getlist(_keyword);
                    });
                }else{
                    ayerAlert(res.msg);
                }

            }
            ,error: function(){
                layerAlert('系统出错，请联系管理员');
            }
        });
    });
    $(function(){
        getlist(_keyword);
        $('#search').click(function(){
            _page = 1;
            table.destroy();
            var keyword = $('#keyword').val();
            getlist(keyword);
        });
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
        //删除
        $('#btn_del').click(function(){
            layerConfirm('是否删除',function(){
                var chk_value =[];
                $('input[name="checkboxed"]:checked').each(function(){
                    chk_value.push($(this).val());
                });
                $.ajax({
                    type: 'post',
                    cache: false,
                    url: '{:url("admin/Tencent/delteTencent")}',
                    data: {ids: chk_value},
                    success: function(data){
                        if(data.code == 0){
                            layerAlert('删除成功');
                        }
                    }
                });
            },function(){
            })
        });
        $('#select').change(function(){
            var _id=  $("#select").val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Tencent/getCategoryList")}',
                data: {id: _id},
                success: function(data) {
                    if (data.code == "0") {
                        $("#select2 option").remove();
                        var html = '<option value="">请选择...</option>';
                        $("#select2").append(html);
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.categoryname + '</option>';
                            $("#select2").append(html);
                        });
                        table.destroy();
                        getlist(_keyword,_id);
                    }
                }
            });
        })
    });
    $('#select2').change(function(){
        var _id2=  $("#select2").val();
        table.destroy();
        getlist(_keyword,'',_id2);
    });
    function getlist(_keyword,_category,_category2)
    {
        $.ajax({
            type: 'post', cache: false,
            url:'{:url("admin/Tencent/getTencentList")}',
            data: {keyword:_keyword,category:_category,category2:_category2,page:_page,size:_size},
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;"><img style="width: 45px;height: 45px;" src="'+item.pic+'" alt=""></td>';
                        html+='<td style="vertical-align: middle;">'+item.name+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.ghid+'<i ghid="'+item.ghid+'" class="fa fa-qrcode qrcode"></i></td>';
                        html+='<td style="vertical-align: middle;">'+item.appid+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.category+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.category2+'</td>';
                        html+='<td style="vertical-align: middle;"><a onclick="checkGzList('+item.id+')" style="color: #40AFFE;margin-right: 5px;" href="#">关注回复</a>|<a onclick="checkPtList('+item.id+')" style="color: #18bc9c;margin-left: 5px;" href="#">普通回复</a></td>';
                        if(item.is_verify=="0")
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;"><div style="width: 10px;height: 10px;float:left;background: #18bc9c;border-radius: 50%;margin-top: 5px;"></div>已认证</span></td>';
                        else
                            html+='<td style="vertical-align: middle;"><span style="color: red;">未认证</span></td>';
                        html+='<td style="vertical-align: middle;">'+item.scan_phone+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.createtime+'</td>';
                        html+='<td style="vertical-align: middle;text-align: center">';
                        html+='<div class="btn-group">';
                        html+=' <button onclick="toedit('+item.id+')" type="button" class="btn" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-edit"></i></button>';
                        html+='</div>';
                        html+='</td>';
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    $('.fa-qrcode').bind("click",function(){
                        var _qrcode = $(this).attr('ghid');
                        url = 'https://open.weixin.qq.com/qr/code?username='+_qrcode;
                        layerWindow('二维码',url,'35%','60%')
                    });
                    table = $('#example1').DataTable({
                        "paging": false,
                        "searching": false,
                        "info": false,
                        "autoWidth": true,
                    });
                    layerPager(_page,_size,data.count,"footpager","footpagerbind");
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
    function footpagerbind(cpage)
    {
        _page=cpage;
        table.destroy();
        getlist();
    }
    //编辑账号
    function toedit(_id) {
        url = "{:url('tencent/edittencent')}" + "?tencentid=" + _id;
        layerWindow('公众号管理->公众号列表->编辑公众号',url,'40%','80%');
    }
    //查看关注后回复列表
    function checkGzList(_id){
        url = "{:url('tencent/checkGzList')}" + "?tid=" + _id;
        layerWindow('查看回复列表',url,'80%','90%');
    }
    //查看普通回复列表
    function checkPtList(_id){
        url = "{:url('tencent/checkPtList')}" + "?tid=" + _id;
        layerWindow('查看回复列表',url,'80%','90%');
    }
    function relist()
    {
        table.destroy();
        getlist(_keyword);
    }
</script>
</html>